package com.nowcoder.community.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author szq
 * @create 2023-01-20 13:57
 * @description 验证码配置类
 */
@Configuration
public class KaptchaConfig {
    @Bean
    public Producer kaptchaProducer(){
        Properties properties = new Properties();
        properties.setProperty("kaptcha.textproducer.font.color", "black"); //字体颜色
        properties.setProperty("kaptcha.image.width", "110");               //长
        properties.setProperty("kaptcha.image.height", "40");               //宽
        properties.setProperty("kaptcha.textproducer.font.size", "32");     //字体大小
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");//字符范围
        properties.setProperty("kaptcha.textproducer.char.length", "4");    //验证码长度
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Config config = new Config(properties);
        kaptcha.setConfig(config);
        return kaptcha;
    }
}